/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CustomerProfileView.java
 *
 * Created on Apr 3, 2010, 11:35:28 PM
 */

package ticketmaster.presentation.customer;

import java.awt.Color;
import java.util.logging.Level;
import java.util.logging.Logger;
import ticketmaster.presentation.LoginView;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.Collection;
import javax.security.cert.CertificateException;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import ticketmaster.businesslogic.RegisterController;
import ticketmaster.businessobject.LoginUser;
import ticketmaster.dataobject.User;
import ticketmaster.util.StringHelper;
import ticketmaster.dao.DAOFactory;
import ticketmaster.dao.UserDAO;
import ticketmaster.common.UserRoles;
import ticketmaster.dao.PremiumCustomerDAO;
import ticketmaster.dataobject.Customer;
import ticketmaster.dataobject.PremiumCustomer;
import ticketmaster.security.Encryption;
import ticketmaster.util.Validator;
import ticketmaster.util.DateTimeHelper;

/**
 *
 * @author Tingting
 */
public class CustomerProfileView extends CustomerBasePanel {
    private UserDAO userDAO;
    private PremiumCustomerDAO premiumcustomerDAO;
    RegisterController controller = new RegisterController();
    Customer customer = new Customer();
    User user = new User();
    PremiumCustomer premiumcustomer = new PremiumCustomer();


    /** Creates new form CustomerProfileView */
    public CustomerProfileView() {
        initComponents();
        initContexFields();
        setComponentsNotVisibility();
    }

   
    private void setComponentsNotVisibility()
    {
        this.lbPasswordError.setVisible(false);
        this.lbPasswordError1.setVisible(false);
        this.lbAddress1Error.setVisible(false);
        this.lbAddress2Error.setVisible(false);
        this.lbCityError.setVisible(false);
        this.lbEmail2Error.setVisible(false);
        this.lbEmailError.setVisible(false);
        this.lbPhone.setVisible(false);
        this.lbPostcode.setVisible(false);
        this.lbProvinceError.setVisible(false);
        this.lbUserName.setVisible(false);
        this.lbfirstnameError.setVisible(false);
        this.lblastnameError.setVisible(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lbUsername = new javax.swing.JLabel();
        lbUsername1 = new javax.swing.JLabel();
        lbUsername2 = new javax.swing.JLabel();
        lbUsername3 = new javax.swing.JLabel();
        lbUsername4 = new javax.swing.JLabel();
        lbUsername5 = new javax.swing.JLabel();
        lbUsername6 = new javax.swing.JLabel();
        lbUsername7 = new javax.swing.JLabel();
        lbUsername8 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        lbUsername10 = new javax.swing.JLabel();
        lbUsername11 = new javax.swing.JLabel();
        lbUsername12 = new javax.swing.JLabel();
        jBAccept = new javax.swing.JButton();
        lbPasswordError = new javax.swing.JLabel();
        lbUsername9 = new javax.swing.JLabel();
        pfPassword = new javax.swing.JPasswordField();
        pfPassword2 = new javax.swing.JPasswordField();
        lbPasswordError1 = new javax.swing.JLabel();
        lbUserName = new javax.swing.JLabel();
        lbPhone = new javax.swing.JLabel();
        lbAddress1Error = new javax.swing.JLabel();
        lbEmail2Error = new javax.swing.JLabel();
        lbEmailError = new javax.swing.JLabel();
        lblastnameError = new javax.swing.JLabel();
        tfFirstName = new javax.swing.JTextField();
        tfLastName = new javax.swing.JTextField();
        tfEmail = new javax.swing.JTextField();
        tfEmail2 = new javax.swing.JTextField();
        tfAddress1 = new javax.swing.JTextField();
        tfAddress2 = new javax.swing.JTextField();
        tfCity = new javax.swing.JTextField();
        tfProvince = new javax.swing.JTextField();
        tfPostcode = new javax.swing.JTextField();
        tfPhone = new javax.swing.JTextField();
        tfUserName = new javax.swing.JTextField();
        lbPostcode = new javax.swing.JLabel();
        lbProvinceError = new javax.swing.JLabel();
        lbCityError = new javax.swing.JLabel();
        lbAddress2Error = new javax.swing.JLabel();
        lbfirstnameError = new javax.swing.JLabel();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(ticketmaster.TicketMasterApp.class).getContext().getResourceMap(CustomerProfileView.class);
        setBackground(resourceMap.getColor("Form.background")); // NOI18N
        setName("Form"); // NOI18N
        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        lbUsername.setFont(resourceMap.getFont("lbUsername.font")); // NOI18N
        lbUsername.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lbUsername.setText(resourceMap.getString("lbUsername.text")); // NOI18N
        lbUsername.setName("lbUsername"); // NOI18N
        add(lbUsername, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 50, 130, 30));

        lbUsername1.setFont(resourceMap.getFont("lbUsername1.font")); // NOI18N
        lbUsername1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lbUsername1.setText(resourceMap.getString("lbUsername1.text")); // NOI18N
        lbUsername1.setName("lbUsername1"); // NOI18N
        add(lbUsername1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 90, 130, 30));

        lbUsername2.setFont(resourceMap.getFont("lbUsername2.font")); // NOI18N
        lbUsername2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lbUsername2.setText(resourceMap.getString("lbUsername2.text")); // NOI18N
        lbUsername2.setName("lbUsername2"); // NOI18N
        add(lbUsername2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 130, 150, 30));

        lbUsername3.setFont(resourceMap.getFont("lbUsername3.font")); // NOI18N
        lbUsername3.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lbUsername3.setText(resourceMap.getString("lbUsername3.text")); // NOI18N
        lbUsername3.setName("lbUsername3"); // NOI18N
        add(lbUsername3, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 330, 120, 30));

        lbUsername4.setFont(resourceMap.getFont("lbUsername4.font")); // NOI18N
        lbUsername4.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lbUsername4.setText(resourceMap.getString("lbUsername4.text")); // NOI18N
        lbUsername4.setName("lbUsername4"); // NOI18N
        add(lbUsername4, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 370, 130, 30));

        lbUsername5.setFont(resourceMap.getFont("lbUsername5.font")); // NOI18N
        lbUsername5.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lbUsername5.setText(resourceMap.getString("lbUsername5.text")); // NOI18N
        lbUsername5.setName("lbUsername5"); // NOI18N
        add(lbUsername5, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 290, 80, 30));

        lbUsername6.setFont(resourceMap.getFont("lbUsername6.font")); // NOI18N
        lbUsername6.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lbUsername6.setText(resourceMap.getString("lbUsername6.text")); // NOI18N
        lbUsername6.setName("lbUsername6"); // NOI18N
        add(lbUsername6, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 210, 170, 30));

        lbUsername7.setFont(resourceMap.getFont("lbUsername7.font")); // NOI18N
        lbUsername7.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lbUsername7.setText(resourceMap.getString("lbUsername7.text")); // NOI18N
        lbUsername7.setName("lbUsername7"); // NOI18N
        add(lbUsername7, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 410, 90, 30));

        lbUsername8.setFont(resourceMap.getFont("lbUsername8.font")); // NOI18N
        lbUsername8.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lbUsername8.setText(resourceMap.getString("lbUsername8.text")); // NOI18N
        lbUsername8.setName("lbUsername8"); // NOI18N
        add(lbUsername8, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 170, 180, 30));

        jLabel1.setForeground(resourceMap.getColor("jLabel1.foreground")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 20, -1, -1));

        lbUsername10.setFont(resourceMap.getFont("lbUsername10.font")); // NOI18N
        lbUsername10.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lbUsername10.setText(resourceMap.getString("lbUsername10.text")); // NOI18N
        lbUsername10.setName("lbUsername10"); // NOI18N
        add(lbUsername10, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 490, 180, 30));

        lbUsername11.setFont(resourceMap.getFont("lbUsername11.font")); // NOI18N
        lbUsername11.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lbUsername11.setText(resourceMap.getString("lbUsername11.text")); // NOI18N
        lbUsername11.setName("lbUsername11"); // NOI18N
        add(lbUsername11, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 530, 180, 30));

        lbUsername12.setFont(resourceMap.getFont("lbUsername12.font")); // NOI18N
        lbUsername12.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lbUsername12.setText(resourceMap.getString("lbUsername12.text")); // NOI18N
        lbUsername12.setName("lbUsername12"); // NOI18N
        add(lbUsername12, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 450, 140, 30));

        jBAccept.setBackground(resourceMap.getColor("jBAccept.background")); // NOI18N
        jBAccept.setFont(resourceMap.getFont("jBAccept.font")); // NOI18N
        jBAccept.setForeground(resourceMap.getColor("jBAccept.foreground")); // NOI18N
        jBAccept.setText(resourceMap.getString("jBAccept.text")); // NOI18N
        jBAccept.setName("jBAccept"); // NOI18N
        jBAccept.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBAcceptActionPerformed(evt);
            }
        });
        add(jBAccept, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 580, 150, 40));

        lbPasswordError.setForeground(resourceMap.getColor("lbPasswordError.foreground")); // NOI18N
        lbPasswordError.setText(resourceMap.getString("lbPasswordError.text")); // NOI18N
        lbPasswordError.setName("lbPasswordError"); // NOI18N
        add(lbPasswordError, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 490, -1, 30));

        lbUsername9.setFont(resourceMap.getFont("lbUsername9.font")); // NOI18N
        lbUsername9.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        lbUsername9.setText(resourceMap.getString("lbUsername9.text")); // NOI18N
        lbUsername9.setName("lbUsername9"); // NOI18N
        add(lbUsername9, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 250, 150, 30));

        pfPassword.setFont(resourceMap.getFont("tfPhone.font")); // NOI18N
        pfPassword.setName("pfPassword"); // NOI18N
        add(pfPassword, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 490, 421, 30));

        pfPassword2.setFont(resourceMap.getFont("tfPhone.font")); // NOI18N
        pfPassword2.setName("pfPassword2"); // NOI18N
        add(pfPassword2, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 530, 421, 30));

        lbPasswordError1.setForeground(resourceMap.getColor("lbPasswordError1.foreground")); // NOI18N
        lbPasswordError1.setText(resourceMap.getString("lbPasswordError1.text")); // NOI18N
        lbPasswordError1.setName("lbPasswordError1"); // NOI18N
        add(lbPasswordError1, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 530, -1, 30));

        lbUserName.setForeground(resourceMap.getColor("lbUserName.foreground")); // NOI18N
        lbUserName.setText(resourceMap.getString("lbUserName.text")); // NOI18N
        lbUserName.setName("lbUserName"); // NOI18N
        add(lbUserName, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 450, -1, 30));

        lbPhone.setForeground(resourceMap.getColor("lbPhone.foreground")); // NOI18N
        lbPhone.setText(resourceMap.getString("lbPhone.text")); // NOI18N
        lbPhone.setName("lbPhone"); // NOI18N
        add(lbPhone, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 410, -1, 30));

        lbAddress1Error.setForeground(resourceMap.getColor("lbAddress1Error.foreground")); // NOI18N
        lbAddress1Error.setText(resourceMap.getString("lbAddress1Error.text")); // NOI18N
        lbAddress1Error.setName("lbAddress1Error"); // NOI18N
        add(lbAddress1Error, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 210, -1, 30));

        lbEmail2Error.setForeground(resourceMap.getColor("lbEmail2Error.foreground")); // NOI18N
        lbEmail2Error.setText(resourceMap.getString("lbEmail2Error.text")); // NOI18N
        lbEmail2Error.setName("lbEmail2Error"); // NOI18N
        add(lbEmail2Error, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 170, -1, 30));

        lbEmailError.setForeground(resourceMap.getColor("lbEmailError.foreground")); // NOI18N
        lbEmailError.setText(resourceMap.getString("lbEmailError.text")); // NOI18N
        lbEmailError.setName("lbEmailError"); // NOI18N
        add(lbEmailError, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 130, -1, 30));

        lblastnameError.setForeground(resourceMap.getColor("lblastnameError.foreground")); // NOI18N
        lblastnameError.setText(resourceMap.getString("lblastnameError.text")); // NOI18N
        lblastnameError.setName("lblastnameError"); // NOI18N
        add(lblastnameError, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 90, -1, 30));

        tfFirstName.setFont(resourceMap.getFont("tfPhone.font")); // NOI18N
        tfFirstName.setName("tfFirstName"); // NOI18N
        add(tfFirstName, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 50, 421, 30));

        tfLastName.setFont(resourceMap.getFont("tfPhone.font")); // NOI18N
        tfLastName.setName("tfLastName"); // NOI18N
        add(tfLastName, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 90, 421, 30));

        tfEmail.setFont(resourceMap.getFont("tfPhone.font")); // NOI18N
        tfEmail.setName("tfEmail"); // NOI18N
        add(tfEmail, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 130, 421, 30));

        tfEmail2.setFont(resourceMap.getFont("tfPhone.font")); // NOI18N
        tfEmail2.setName("tfEmail2"); // NOI18N
        add(tfEmail2, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 170, 421, 30));

        tfAddress1.setFont(resourceMap.getFont("tfPhone.font")); // NOI18N
        tfAddress1.setName("tfAddress1"); // NOI18N
        add(tfAddress1, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 210, 421, 30));

        tfAddress2.setFont(resourceMap.getFont("tfPhone.font")); // NOI18N
        tfAddress2.setName("tfAddress2"); // NOI18N
        add(tfAddress2, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 250, 421, 30));

        tfCity.setFont(resourceMap.getFont("tfPhone.font")); // NOI18N
        tfCity.setName("tfCity"); // NOI18N
        add(tfCity, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 290, 421, 30));

        tfProvince.setFont(resourceMap.getFont("tfPhone.font")); // NOI18N
        tfProvince.setName("tfProvince"); // NOI18N
        add(tfProvince, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 330, 421, 30));

        tfPostcode.setFont(resourceMap.getFont("tfPhone.font")); // NOI18N
        tfPostcode.setName("tfPostcode"); // NOI18N
        add(tfPostcode, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 370, 421, 30));

        tfPhone.setFont(resourceMap.getFont("tfPhone.font")); // NOI18N
        tfPhone.setName("tfPhone"); // NOI18N
        add(tfPhone, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 410, 421, 30));

        tfUserName.setFont(resourceMap.getFont("tfPhone.font")); // NOI18N
        tfUserName.setName("tfUserName"); // NOI18N
        add(tfUserName, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 450, 421, 30));

        lbPostcode.setForeground(resourceMap.getColor("lbPostcode.foreground")); // NOI18N
        lbPostcode.setText(resourceMap.getString("lbPostcode.text")); // NOI18N
        lbPostcode.setName("lbPostcode"); // NOI18N
        add(lbPostcode, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 370, -1, 30));

        lbProvinceError.setForeground(resourceMap.getColor("lbProvinceError.foreground")); // NOI18N
        lbProvinceError.setText(resourceMap.getString("lbProvinceError.text")); // NOI18N
        lbProvinceError.setName("lbProvinceError"); // NOI18N
        add(lbProvinceError, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 330, -1, 30));

        lbCityError.setForeground(resourceMap.getColor("lbCityError.foreground")); // NOI18N
        lbCityError.setText(resourceMap.getString("lbCityError.text")); // NOI18N
        lbCityError.setName("lbCityError"); // NOI18N
        add(lbCityError, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 290, -1, 30));

        lbAddress2Error.setForeground(resourceMap.getColor("lbAddress2Error.foreground")); // NOI18N
        lbAddress2Error.setText(resourceMap.getString("lbAddress2Error.text")); // NOI18N
        lbAddress2Error.setName("lbAddress2Error"); // NOI18N
        add(lbAddress2Error, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 250, -1, 30));

        lbfirstnameError.setForeground(resourceMap.getColor("lbfirstnameError.foreground")); // NOI18N
        lbfirstnameError.setText(resourceMap.getString("lbfirstnameError.text")); // NOI18N
        lbfirstnameError.setName("lbfirstnameError"); // NOI18N
        add(lbfirstnameError, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 50, -1, 30));
    }// </editor-fold>//GEN-END:initComponents

    private void jBAcceptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAcceptActionPerformed
        // button "Accept and Continue":
       
        String username = this.tfUserName.getText();
        String password = StringHelper.CharArrayToString(this.pfPassword.getPassword());
        String password2 = StringHelper.CharArrayToString(this.pfPassword2.getPassword());
        String firstname = this.tfFirstName.getText();
        String lastname = this.tfLastName.getText();
        String email = this.tfEmail.getText();
        String email2 = this.tfEmail2.getText();
        String address1 = this.tfAddress1.getText();
        String address2 = this.tfAddress2.getText();
        String city = this.tfCity.getText();
        String province = this.tfProvince.getText();
        String postcode = this.tfPostcode.getText();
        String phone = this.tfPhone.getText();

        boolean validLabel= true;
        boolean validphone = true;

        
       
        if (!password.equals("")){
            if((password.length() < 5) ||(password.length()>12)){
                this.lbPasswordError.setVisible(true);
                validLabel= false;
            } else if((!(password.equals(password2))) && (password.length() >= 5) && (password.length() <= 12)){
                this.lbPasswordError1.setVisible(true);
                this.lbPasswordError.setVisible(false);
                validLabel= false;
            } else{
                this.lbPasswordError.setVisible(false);
                this.lbPasswordError1.setVisible(false);
                user.setPassword(Encryption.md5(password));
            }
        }
        

        if(!Validator.validateStringFormat(username)){
            this.lbUserName.setText("The format is invalid");
            this.lbUserName.setVisible(true);
            validLabel= false;
        } else if (username.equals("")){
            this.lbUserName.setVisible(true);
            validLabel= false;
        } else{
            this.lbUserName.setVisible(false);
            user.setUsername(username);
            user.setUserRoleID(UserRoles.Customer.ordinal());
        }



        if(!Validator.validateNameFormat(firstname)) {
            this.lbfirstnameError.setText("The information is invalid");
            this.lbfirstnameError.setVisible(true);
            validLabel= false;
        } else if(firstname.equals("")){
            this.lbfirstnameError.setVisible(true);
            validLabel= false;
        } else{
            this.lbfirstnameError.setVisible(false);
            customer.setFirstName(firstname);
        }

        if(!Validator.validateNameFormat(lastname)) {
            this.lblastnameError.setText("The information is invalid");
            this.lblastnameError.setVisible(true);
            validLabel= false;
        } else if(lastname.equals("")){
            this.lblastnameError.setVisible(true);
            validLabel= false;
        } else{
            this.lblastnameError.setVisible(false);
            customer.setLastName(lastname);
        }

        if(email.equals("")){
            this.lbEmailError.setVisible(true);
            validLabel= false;
        } else if((!Validator.validateEmailFormat(email)) || (!email.contains("@")) || (!email.contains("."))){
            this.lbEmailError.setText("The information is invalid");
            this.lbEmailError.setVisible(true);
            validLabel= false;
        } else if((email.contains("@")) && (email.contains(".")) && (!(email.equals(email2)))){
            this.lbEmailError.setVisible(false);
            this.lbEmail2Error.setVisible(true);
            validLabel= false;
        } else if((email.contains("@")) && (email.contains(".")) && (email.equals(email2))){
            this.lbEmailError.setVisible(false);
            this.lbEmail2Error.setVisible(false);
            customer.setEmailAddress(email);

        }

        if(!Validator.validateAddressFormat(address2)){
            this.lbAddress1Error.setText("The information is invalid");
            this.lbAddress1Error.setVisible(true);
            validLabel= false;
        } else if(address1.equals("")){
            this.lbAddress1Error.setVisible(true);
            validLabel= false;
        } else{
            this.lbAddress1Error.setVisible(false);
            customer.setAddressLine1(address1);
        }

        if(!Validator.validateNameFormat(city)){
            this.lbCityError.setText("The information is invalid");
            this.lbCityError.setVisible(true);
            validLabel= false;
        } else if(city.equals("")){
            this.lbCityError.setVisible(true);
            validLabel= false;
        } else{
            this.lbCityError.setVisible(false);
            customer.setCity(city);
        }


        if(!Validator.validateNameFormat(province)){
            this.lbProvinceError.setText("The information is invalid");
            this.lbProvinceError.setVisible(true);
            validLabel= false;
        } else if(province.equals("")){
            this.lbProvinceError.setVisible(true);
            validLabel= false;
        } else{
            this.lbProvinceError.setVisible(false);
            customer.setProvince(province);
        }

        if(!Validator.validatePostcodeFormat(postcode)){
            this.lbPostcode.setText("The information is invalid");
            this.lbPostcode.setVisible(true);
            validLabel= false;
        } else if(postcode.equals("")){
            this.lbPostcode.setVisible(true);
            validLabel= false;
        } else if(postcode.length() != 6){
            this.lbPostcode.setText("6 characters");
            this.lbPostcode.setVisible(true);
            validLabel= false;
        } else{
            this.lbPostcode.setVisible(false);
            customer.setPostcode(postcode);
        }



                if(!Validator.validatePhoneNumberFormat(phone)){
            this.lbPhone.setText("The information is invalid");
            this.lbPhone.setVisible(true);
            validLabel= false;
         }
        else if(phone.equals("")){
            this.lbPhone.setVisible(false);
            customer.setPhoneNo(phone);
        }
        else if(phone.length() != 10){
            this.lbPhone.setText("10 numbers");
            this.lbPhone.setVisible(true);
            validLabel= false;
        }
        else{
            for (int i = 0; i < 10; ++i){
                if(!Character.isDigit(phone.charAt(i))){
                    validphone = false;
                    validLabel = false;
                }
            }
            if(validphone){
                this.lbPhone.setVisible(false);
                customer.setPhoneNo(phone);
            }
        }


        if(!Validator.validateAddressFormat(address2)){
            this.lbAddress2Error.setVisible(true);
            validLabel= false;
        } else{
            this.lbAddress2Error.setVisible(false);
            customer.setAddressLine2(address2);
        }


        if(validLabel){
            if(controller.updateRegCustomer(customer)){
                 controller.updateRegUser(user);
                JOptionPane.showMessageDialog(this,"Successfully update the your inforamtion !");
            }
        }
    

        ticketmaster.businessobject.User Loguser = LoginUser.getUser();

        int userID = Loguser.getUserID();
        //int userID = 33;
//
//        premiumcustomer.setCustomerID(userID);
//
//        if((this.jCheckBoxPremuim.isSelected()) && (validLabel)) {
//            //the credit card page
//           Collection<PremiumCustomer> validPremiumCustomer = this.getPremiumCustomerDAO().getPremiumCustomersDO(premiumcustomer);
//           if(validPremiumCustomer.size() != 0){
//               JOptionPane.showMessageDialog(this,"You are already a premium member !");
//               validLabel= false;
//            }
//            premiumcustomer.setRegistrationDate(DateTimeHelper.getCurrentDateTime());
//            premiumcustomer.setPoints(30);
//            controller.RegisterPremiumCustomer(premiumcustomer);
//
//        } else if((!this.jCheckBoxPremuim.isSelected()) && (validLabel))
//        {
//
//
//        }
    }//GEN-LAST:event_jBAcceptActionPerformed

//     public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                JFrame frame = new JFrame();
//                CustomerProfileView crp = new CustomerProfileView();
//                frame.setSize(1000, 800);
//                frame.add(crp);
//                frame.setVisible(true);
//           }
//        });
//    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBAccept;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel lbAddress1Error;
    private javax.swing.JLabel lbAddress2Error;
    private javax.swing.JLabel lbCityError;
    private javax.swing.JLabel lbEmail2Error;
    private javax.swing.JLabel lbEmailError;
    private javax.swing.JLabel lbPasswordError;
    private javax.swing.JLabel lbPasswordError1;
    private javax.swing.JLabel lbPhone;
    private javax.swing.JLabel lbPostcode;
    private javax.swing.JLabel lbProvinceError;
    private javax.swing.JLabel lbUserName;
    private javax.swing.JLabel lbUsername;
    private javax.swing.JLabel lbUsername1;
    private javax.swing.JLabel lbUsername10;
    private javax.swing.JLabel lbUsername11;
    private javax.swing.JLabel lbUsername12;
    private javax.swing.JLabel lbUsername2;
    private javax.swing.JLabel lbUsername3;
    private javax.swing.JLabel lbUsername4;
    private javax.swing.JLabel lbUsername5;
    private javax.swing.JLabel lbUsername6;
    private javax.swing.JLabel lbUsername7;
    private javax.swing.JLabel lbUsername8;
    private javax.swing.JLabel lbUsername9;
    private javax.swing.JLabel lbfirstnameError;
    private javax.swing.JLabel lblastnameError;
    private javax.swing.JPasswordField pfPassword;
    private javax.swing.JPasswordField pfPassword2;
    private javax.swing.JTextField tfAddress1;
    private javax.swing.JTextField tfAddress2;
    private javax.swing.JTextField tfCity;
    private javax.swing.JTextField tfEmail;
    private javax.swing.JTextField tfEmail2;
    private javax.swing.JTextField tfFirstName;
    private javax.swing.JTextField tfLastName;
    private javax.swing.JTextField tfPhone;
    private javax.swing.JTextField tfPostcode;
    private javax.swing.JTextField tfProvince;
    private javax.swing.JTextField tfUserName;
    // End of variables declaration//GEN-END:variables

     private void initContexFields()
    {
         //problem password and userID
        ticketmaster.businessobject.User Loguser = LoginUser.getUser();
        //int userID = 33;
        int userID = LoginUser.getUser().getUserID();

        user.setUserID(userID);
        customer.setCustomerID(userID);
      //  premiumcustomer.setCustomerID(userID);
        user = controller.findRegUser(user);
        customer = controller.fingRegCustomer(customer);
        String Regpassword = user.getPassword();
        String Regusername = user.getUsername();
        String RegFirstname = customer.getFirstName();
        String RegLastname = customer.getLastName();
        String Regemail = customer.getEmailAddress();
        String Regaddress1 = customer.getAddressLine1();
        String Regaddress2 = customer.getAddressLine2();
        String Regcity = customer.getCity();
        String Regprovince = customer.getProvince();
        String Regpostcode = customer.getPostcode();
        String Regphone = customer.getPhoneNo();

        this.tfUserName.setText(Regusername);
        this.tfUserName.setEnabled(false);
        this.tfUserName.setDisabledTextColor(Color.black);
        
        this.pfPassword.setText("");
        this.pfPassword2.setText("");
        this.tfFirstName.setText(RegFirstname);
        this.tfLastName.setText(RegLastname);
        this.tfEmail.setText(Regemail);
        this.tfEmail2.setText(Regemail);
        this.tfAddress1.setText(Regaddress1);
        this.tfAddress2.setText(Regaddress2);
        this.tfCity.setText(Regcity);
        this.tfProvince.setText(Regprovince);
        this.tfPostcode.setText(Regpostcode);
        this.tfPhone.setText(Regphone);
        this.tfAddress1.setText(Regaddress1);
       
    }

   public UserDAO getUserDAO()
    {
        if(userDAO == null)
            userDAO = DAOFactory.getInstance().getUserDAO();
        return userDAO;
    }

   public PremiumCustomerDAO getPremiumCustomerDAO(){
       if(premiumcustomerDAO == null)
           premiumcustomerDAO = DAOFactory.getInstance().getPremiumCustomerDAO();
       return premiumcustomerDAO;
   }

}
